package matchthreegame.utils;


import java.util.List;

import matchthreegame.dataBase.DBManagerHelper;

import com.smartfoxserver.v2.entities.variables.UserVariable;

public class Bot {
	
	private String name;
	public int wins;
	public int losses;
	public int rank;
	public int heroType;
	public int heroProduces;
	public int heroAttack;
	public int botLevel;
	
	public Bot(String name) {
		
		this.name = name;
		
	}
	
	public String getBotName() {
		
		return this.name;
		
	}
	
	public void populateStatsFromUserVariables(List<UserVariable> userVariablesList ) {
		
		this.wins = getVariableForKey(DBManagerHelper.PLAYER_WINS, userVariablesList).getIntValue();
		this.losses = getVariableForKey(DBManagerHelper.PLAYER_LOSSES, userVariablesList).getIntValue();
		this.rank = getVariableForKey(DBManagerHelper.PLAYER_RANK, userVariablesList).getIntValue();
		this.heroType = getVariableForKey(DBManagerHelper.HERO_TYPE, userVariablesList).getIntValue();
		this.botLevel = getVariableForKey(DBManagerHelper.BOT_LEVEL, userVariablesList).getIntValue();
		this.heroProduces = getVariableForKey(DBManagerHelper.HERO_PRODUCES, userVariablesList).getIntValue();
		this.heroAttack = getVariableForKey(DBManagerHelper.HERO_ATTACK, userVariablesList).getIntValue();
		
	}
	
	private UserVariable getVariableForKey(String variableKey, List<UserVariable> userVariables) {
		
		UserVariable userVariableToReturn = null;
		
		for (UserVariable userVariable : userVariables) {
			if ( userVariable.getName().equals(variableKey) ) {
				userVariableToReturn = userVariable;
				break;
			}
		}
		
		return userVariableToReturn;
		
	}
			
			

}
